package com.bltec.emergency.mapper;

import com.bltec.emergency.model.ForeignSorties;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
@Mapper
public interface ForeignSortiesMapper {
    //插入一条foreignSorties记录
    @Insert("insert into foreign_sorties (helicopter_name,daily_fee,fuel_price,rescue_area,rescue_begin_time,rescue_end_time,rescue_fuel,rescue_num," +
            "create_by,create_time,enable) " +
            "values(#{helicopterName},#{dailyFee},#{fuelPrice},#{rescueArea},#{rescueBeginTime},#{rescueEndTime},#{rescueFuel},#{rescueNum}," +
            "#{createBy},#{createTime},#{enable})")
    boolean insert(ForeignSorties foreignSorties);

    //通过id设置一条记录为不可用
    @Update("update foreign_sorties set enable=0 where id=#{id}")
    boolean setDisableById(Long id);

    //通过id更新一条记录
    @Update("update foreign_sorties set helicopter_name=#{helicopterName},daily_fee=#{dailyFee},fuel_price=#{fuelPrice},rescue_area=#{rescueArea}," +
            "rescue_begin_time=#{rescueBeginTime},rescue_end_time=#{rescueEndTime},rescue_fuel=#{rescueFuel},rescue_num=#{rescueNum}," +
            "update_by=#{updateBy},update_time=#{updateTime} where id=#{id}")
    boolean updateForeignSortiesById(ForeignSorties foreignSorties);

    //查找符合id字段的记录
    @Select("select id,helicopter_name,daily_fee,fuel_price,rescue_area,rescue_begin_time,rescue_end_time,rescue_fuel,rescue_num," +
            "create_by,create_time,update_by,update_time,enable" +
            " from foreign_sorties where id =#{id} and enable=1")
    ForeignSorties getForeignSortiesById(Long id);

    //查找所有记录
    @Select("select id,helicopter_name,daily_fee,fuel_price,rescue_area,rescue_begin_time,rescue_end_time,rescue_fuel,rescue_num," +
            "create_by,create_time,update_by,update_time,enable" +
            " from foreign_sorties where enable=1")
    List<ForeignSorties> selectAll();
}